const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载 
   */
  onLoad: function (options) {
    this.checkLogin();//验证是否登录
  },
  checkLogin() {
    let url = app.getNetAddresss("member.login.check-login");
    app._getNetWork({
      url: url,
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          let {path,params,...query} = this.options;
          let wx_token = wx.getStorageSync('wx_token');
          url = app.globalData.host + `/addons/yun_shop/?menu#${path}`;
          if(params) url = url + '/' + params;
          url = url + '?i=' + app.globalData.uniacid;
          if(query) {
            let otherQuery = this.objectToQueryString(query);
            url = url + otherQuery;
          } 
          url = `${url}&min_token=${wx_token}`;//自营商城免登录
          
          this.setData({
            link: url
          })
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  objectToQueryString(obj) {
    const keys = Object.keys(obj);
    const values = Object.values(obj);
    const queryString = keys.map((key, index) => {
      return `&${key}=${values[index]}`;
    }).join('');
    return queryString;
  },

  h5Method(e){
    app.tips(e)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  onShareTimeline(){},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let { path, shareType, room_id } = this.options;
    return {
      path: `/mircoApp/shop-h5-page/index?path=${path}&shareType=${shareType}&room_id=${room_id}`
    }
  },
});